﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace Bussiness_Objects
{
    /// <summary>
    /// Thong tin table CT_PHIEUMUONSACH
    /// ---CT_PHIEUMUONSACH(SoPM,MaCuonSach)
    /// </summary>
    public class CTPhieuMuonSach : BusinessObjects
    {
        public CTPhieuMuonSach()
        {            
            SoPM = int.MaxValue;
            MaCuonSach = int.MaxValue;
        }

        public CTPhieuMuonSach(int _soPm, int _maCuonSach)
        {
            SoPM = _soPm;
            MaCuonSach = _maCuonSach;
        }

        public override void SetParameterInsert()
        {
            parms = new object[2];
            SqlParameter _parm = new SqlParameter(parSoPM, SoPM);
            parms[0] = _parm;

            _parm = new SqlParameter(parMaCuonSach, MaCuonSach);
            parms[1] = _parm;           
        }

        public void SetDataUpdate(int _soPM, int _maCuonSach)
        {
            SoPM_new = _soPM;
            MaCuonSach_new = _maCuonSach;
        }

        public override void SetParameterUpdate()
        {            
            parms = new object[5];
            SqlParameter _parm = new SqlParameter(parSoPM + "_old", SoPM);
            parms[0] = _parm;

            _parm = new SqlParameter(parMaCuonSach + "_old", MaCuonSach);
            parms[1] = _parm;

            _parm = new SqlParameter(parSoPM + "_new", SoPM_new);
            parms[2] = _parm;

            _parm = new SqlParameter(parMaCuonSach + "_new", MaCuonSach_new);
            parms[3] = _parm;

            _parm = new SqlParameter(parTinhTrang, TinhTrang);
            parms[4] = _parm;
        }

        /// <summary>
        /// Store Procedure thuc hien delete voi 2 tham so (SoPM, MaCuonSach)
        /// </summary>
        public void SetParameterDeleteByKey()
        {
            parms = new object[2];
            SqlParameter _parm = new SqlParameter(parSoPM, SoPM);
            parms[0] = _parm;

            _parm = new SqlParameter(parMaCuonSach, MaCuonSach);
            parms[1] = _parm;
        }

        /// <summary>
        /// Store Procedure thuc hien delete voi 1 tham so (SoPM)
        /// </summary>
        public void SetParameterDeleteByID()
        {
            parms = new object[1];
            SqlParameter _parm = new SqlParameter(parSoPM, SoPM);
            parms[0] = _parm;
        }

        /// <summary>
        /// Store Procedure thuc hien delete voi 1 tham so (MaCuonSach)
        /// </summary>
        public void SetParameterDeleteByMaCuoSach()
        {
            parms = new object[1];
            SqlParameter _parm = new SqlParameter(parMaCuonSach, MaCuonSach);
            parms[0] = _parm;
        }

        public int SoPM { get; set; }
        private const string parSoPM = "@SoPM";
        public int SoPM_new { get; set; }

        public int MaCuonSach { get; set; }
        private const string parMaCuonSach = "@MaCuonSach";
        public int MaCuonSach_new { get; set; }

        public int TinhTrang { get; set; }
        private const string parTinhTrang = "@TinhTrang";
    }
}
